package com.github.wxiaoqi.security.biz.biz;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.wxiaoqi.security.biz.entity.BhFunction;
import com.github.wxiaoqi.security.biz.entity.BhTask;
import com.github.wxiaoqi.security.biz.mapper.BhFunctionMapper;
import com.github.wxiaoqi.security.biz.mapper.BhTaskMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.util.EntityUtils;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * 职能表    存储职能信息
 *
 * @author Mr.AG
 * @email 463540703@qq.com
 * @date 2018-05-16 10:29:10
 */
@Service
public class BhFunctionBiz extends BaseBiz<BhFunctionMapper,BhFunction> {
	@Autowired
	private BhFunctionMapper bhFunctionMapper;
	@Autowired
	private BhTaskMapper bhTaskMapper;
	
	public List<Map<String, Object>> queryAll() throws Exception{
		List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
		BhFunction function = new BhFunction();
		function.setParentid("-1");
		List<BhFunction> list = bhFunctionMapper.select(function);
		for (BhFunction bhFunction : list) {
			Map<String, Object> chMap = EntityUtils.beanToMap(bhFunction);
			BhFunction func = new BhFunction();
			func.setParentid(bhFunction.getParentid());
			List<BhFunction> chList = bhFunctionMapper.select(func);
			chMap.put("children", chList);
			listMap.add(chMap);
		}
		return listMap;
	}
	/**
	 * 关注的职位匹配悬赏
	 */
	public int queryFunctionRewardCount(Map<String, Object> req) throws Exception{
		String attentionIndustry = (String) req.get("companyFunction");
		if(null == attentionIndustry || "".equals(attentionIndustry)){
			return 0;
		}
        String[] industrys = attentionIndustry.split(",");
        List<String> list = new ArrayList<String>(Arrays.asList(industrys));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("companyFunction", attentionIndustry);
		int amount = bhTaskMapper.queryTaskcompanyFunction(list);
        return amount;
	}
}